package com.work.service.impl;

import com.work.dao.GoodsTypeDao;
import com.work.pojo.GoodsType;
import com.work.service.GoodsTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 商品类型服务impl
 *
 * @author gy
 * &#064;date 2022/09/29
 * @version 1.0.0
 * @since 1.0.0
 */
@Service
@Transactional(rollbackFor = Exception.class,readOnly = true,propagation = Propagation.SUPPORTS)
public class GoodsTypeServiceImpl implements GoodsTypeService {
	@Autowired
	private GoodsTypeDao goodsTypeDao;
	@Override
	public List<GoodsType> getGoodsTypeByLevel(int level) {
		return goodsTypeDao.getGoodsTypeByLevel(level);
	}

	@Override
	public List<GoodsType> GoodsTypelist() {
		List<GoodsType> list = goodsTypeDao.GoodsTypelist();
		for (GoodsType goodsType : list) {
			goodsType.setParentName( "无" );
		}
		return list;
	}

	@Override
	@Transactional(rollbackFor = Exception.class)
	public void addGoodsType(int parent, String typename) {
		int i = parent + 1;
		goodsTypeDao.addGoodsType(parent,typename,i);

	}

	@Override
	public List<GoodsType> goodstypelist() {
		return goodsTypeDao.goodstypelist();
	}
}
